package com.tutor.lzm;

import android.app.Application;
import android.os.Build;
import android.os.StrictMode;


import com.squareup.picasso.LruCache;
import com.squareup.picasso.Picasso;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by zzgpc on 2017-8-27.
 * MyApplication
 */
public class MyApplication extends Application {

    public static MyApplication mInstanc;

    public static MyApplication getInstance() {
        return mInstanc;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstanc = this;
        new AppSession(getApplicationContext());
        initPicasso();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }


    }

    /**
     * 设置picasso全局，初始化
     */
    private void initPicasso() {
        //配置全局的picasso instance
        Picasso.Builder builder = new Picasso.Builder(this);
        //配置缓存大小
        LruCache cache = new LruCache(5 * 1024 * 1024);
        builder.memoryCache(cache);
        //配置线程池
        ExecutorService executorService = Executors.newFixedThreadPool(8);
        builder.executor(executorService);
        //构造picasso
        Picasso picasso = builder.build();
        //设置全局单例picasso
        Picasso.setSingletonInstance(picasso);
    }
}
